use sea_orm::entity::prelude::*;
use salvo::prelude::*;
use serde::{Deserialize, Serialize};
use chrono::NaiveDateTime;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "menu")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: String,
    pub name: String,
    pub code: String,
    pub path: Option<String>,
    pub component: Option<String>,
    pub icon: Option<String>,
    pub sort: i32,
    pub order_num: i32,
    pub parent_id: Option<String>,
    pub is_hidden: bool,
    pub tenant_id: Option<i64>,
    pub create_time: NaiveDateTime,
    pub create_by: String,
    pub update_time: NaiveDateTime,
    pub update_by: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

#[derive(Serialize, Deserialize, Extractible, Debug)]
#[salvo(extract(default_source(from = "body", parse = "json")))]
pub struct Menu {
    pub id: String,
    pub name: String,
    pub code: String,
    pub path: Option<String>,
    pub component: Option<String>,
    pub icon: Option<String>,
    pub sort: i32,
    pub parent_id: Option<String>,
    pub is_hidden: bool,
    pub tenant_id: Option<i64>,
    pub create_time: NaiveDateTime,
    pub create_by: String,
    pub update_time: NaiveDateTime,
    pub update_by: String,
}

#[derive(Serialize, Deserialize, Debug, ToSchema)]
pub struct SafeMenu {
    pub id: String,
    pub name: String,
    pub code: String,
    pub path: Option<String>,
    pub component: Option<String>,
    pub icon: Option<String>,
    pub sort: i32,
    pub parent_id: Option<String>,
    pub is_hidden: bool,
    pub tenant_id: Option<i64>,
}

#[derive(Serialize, Deserialize, Debug, ToSchema)]
pub struct MenuTree {
    pub id: String,
    pub name: String,
    pub code: String,
    pub path: Option<String>,
    pub component: Option<String>,
    pub icon: Option<String>,
    pub sort: i32,
    pub parent_id: Option<String>,
    pub is_hidden: bool,
    pub tenant_id: Option<i64>,
    pub children: Vec<MenuTree>,
}
